package com.thread.exe;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

public class StudySemaphore {
	public static void main(String[] args) {
		ExecutorService executorServcie = Executors.newCachedThreadPool();
		Semaphore semaphore = new Semaphore(0);
		semaphore.release();
		for (int i = 0; i < 1; i++) {
			final long num = i;
			executorServcie.submit(new Runnable() {
				@Override
				public void run() {
					try {
						semaphore.acquire();
						
						System.out.println("Accessing: " + num + "|" + semaphore.availablePermits());
						Thread.sleep(10000L);
						semaphore.release();
						System.out.println("Release..." + num);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
			});
		}
		executorServcie.shutdown();
	}
}
